<template>
    <div class="pic page_w_h">
        <ul class="pics">
            <li v-for="(it, i) in pics" :key="i"><img :src="it" @click="choiceImg(it)" alt=""></li>
        </ul>
    </div>


    <div class="preview" v-show="showPreview" @click="closePreview">
        <img :src="showImg" alt="">
    </div>
</template>

<script setup>

import data from '../../assets/data/data'
import { ref, nextTick } from 'vue'


const pics = ref(data.pics)
let showImg = ref('')
let showPreview = ref(false)

function RandomNumBoth(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}

nextTick(() => {
    const lis = document.getElementsByTagName('li')
    let pos_arr = []
    for (let i = 0; i < lis.length; i++) {
        let img = lis[i].children[0]
        let x = RandomNumBoth(-10, 10)
        let y = RandomNumBoth(-10, 10)
        let z = RandomNumBoth(-10, 5)
        let perspective = RandomNumBoth(180, 360)
        img.style.transform = `rotate3d(${x},${y},${z},15deg)`
        lis[i].style.perspective = perspective + 'px'
    }
})

function choiceImg(it) {
    showPreview.value = true
    showImg.value = it
}

function closePreview(){
    showPreview.value = false
}

</script>


<style scoped lang="less">
.pic {
    background: url('../../assets/bg.jpg');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    display: flex;
    justify-content: center;
    align-items: center;

    .pics {
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        width: 80%;
        height: 80%;
        position: relative;

        li {
            width: 33%;
            height: 33%;
            text-align: center;

            img {
                height: 100%;
                display: inline;
                transition: all 1s linear;
            }
        }
    }
}

.preview {
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, .5);
    position: absolute;
    top: 0;
    left: 0;
    animation-name: previewKey;
    animation-duration: 1s;
    animation-delay: 0;

    img {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        height:75%;
    }
}

@keyframes previewKey {
    from {
        width: 0;
        height: 0;
        opacity: 0;
        left: 50%;
        top: 50%;
    }

    to {
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        opacity: 1;
    }
}
</style>